package com.tnf.bc.bground.service.impl;

import com.tnf.bc.bground.certificate.pojo.LoginUser;
import com.tnf.bc.bground.certificate.pojo.SysUser;
import com.tnf.bc.bground.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description: //用户信息查询
 * @author: lzl
 * @create: 2022-11-18 17:17
 **/
@Service
@Transactional
public class UserDetailServiceImpl implements UserDetailsService {

    @Autowired
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        SysUser sysUser = userDao.selectByUserName(userName);
        if (sysUser == null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        List<String> perms = userDao.selectPerms(sysUser.getId());
        return new LoginUser(sysUser, perms) ;
    }
}